package frsf.cidisi.exercise.laberinto.search.util;

public class Par {
	protected int x;
	protected int y;
	
	public Par() {
		this(0, 0);
	}
	
	public Par(int x, int y) {
		this.setX(x);
		this.setY(y);
	}
	
	public Par(Par unPar) {
		this.setX(unPar.getX());
		this.setY(unPar.getY());
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
	
	public Par sumar(Par unPar) {
		return new Par(this.getX() + unPar.getX(), 
					   this.getY() + unPar.getY());
	}
	
	public int medir(Par unPar) {
		int disX = Math.abs(unPar.getX() - this.getX());
		int disY = Math.abs(unPar.getY() - this.getY());
		return disX + disY;
		//return Math.sqrt(Math.pow(disX, 2) + Math.pow(disY, 2));
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (this.getClass() != obj.getClass())
			return false;
		Par other = (Par) obj;
		if (this.x != other.x)
			return false;
		if (this.y != other.y)
			return false;
		return true;
	}

	@Override
	public Object clone() {
		return new Par(x, y);	
	}
	
	public String toString() {
		return "(" + x + ", " + y + ")"; 
	}
}
